$(function(){
	
	var postId = getUrlParam('postId');
	var postType = getUrlParam('postType');
	var isAdmin = true;//是否是管理员??

	getPostInfo(postId,postType);//获取帖子详情
	

	$('.detail-sign').on('click','.sign-btn',function(){
		checkLogin(function(){
			if(!$('.sign-btn').hasClass('disabled')){
				location.href='/duimen/detail/sign-form.html?postId='+postId;
			}
		})
	});
    if($('.sign-btn').hasClass('disabled')){
        console.log($('.sign-btn').hasClass('disabled'));
        $('.fixed-btn').hide();
    }else{
        $(window).scroll(function(){
            if($(window).scrollTop()>20&&$('.fixed-btn').css('opacity')==0) {
                $('.fixed-btn').fadeIn();
            }else if($(window).scrollTop()<20&&$('.fixed-btn').css('opacity')==1){
                $('.fixed-btn').fadeOut();
            }
        })
    }
	
})
var getPostInfo = function(postId,postType,rendorInfo){
	$.ajax({
		type:'GET',
		url: baseurl+'/post/query/info.html',
		dataType: 'jsonp',
		data:{
            postId: postId,
            postType: postType
        }
	}).then(function(data){
        if(data.resultCode==0){
        	console.log(data.result);
            var endTime = new Date(data.result.endTime);
            var postTime = new Date(data.result.postTime);
            var startTime = new Date(data.result.startTime);
            data.result.endTime = endTime.Format('yyyy-MM-dd');
            data.result.postTime = postTime.Format('yyyy-MM-dd');
            data.result.startTime = startTime.Format('yyyy-MM-dd');
            if(data.result.attendFlag==0){
                var nowDate = new Date();

                if(nowDate<endTime){
                    data.result.status = ['我要报名'];
                }else{
                    data.result.status = ['报名已结束','disabled'];
                }
            }else{
                data.result.status = ['已参加','disabled'];
            }
            
            var html = template('tpl_detail_sign', data.result);
            $('.tie-mod').html(html);
            Detail.getCommPraise(data.result);

        	var mySwiper = new Swiper('.swiper-container', {
                speed: 1000,
                spaceBetween: 0,
                autoplay:3000,
                onSlideChangeEnd:function(swiper){
                    var page = $('.tie-mod .page');
                    var length = swiper.wrapper[0].childElementCount;
                    page.html(swiper.activeIndex+1+'/'+length);
                    if(!swiper.autoplaying){
                        swiper.startAutoplay();	
                    }
                }
            });

        }else{
        	console.log(data.resultMsg)
    	}
        if(postType==3){
            $('.header span').html('报名活动详情');
        }else if(postType==1){
            $('header span').html('公告详情');
        }
    })
}